package com.mika.web;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 响应结果数据封装
 *
 * @Author XiaoJiangShi
 * @Date 2022/8/22 10:15
 * @Blog blog.XiaoJiangShi.net/996.mba
 * @Description: 响应结果数据封装
 */
@Data
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private Integer code;  //响应码，1：代表成功，0或其他数字：代表失败
    private String msg;  //响应数据
    private T data;  //响应对象
    private Map map = new HashMap(); //动态数据

    public static <T> Result<T> ok(String msg, T object) {
        Result<T> r = new Result<T>();
        r.code = 1;
        r.msg = msg;
        r.data = object;
        return r;
    }

    public static <T> Result<T> fail(String msg) {
        Result<T> r = new Result<T>();
        r.code = 0;
        r.msg = msg;
        r.data = null;
        return r;
    }

    public Result<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }
}

